package org.lgiavedoni.android.franq.service.phone.location.updatelocation.imp;

import org.lgiavedoni.android.franq.core.envent.Event;
import org.lgiavedoni.android.franq.core.envent.listener.EventListener;
import org.lgiavedoni.android.franq.core.position.PositionManager;
import org.lgiavedoni.android.franq.event.GSMCellChangeEvent;
import org.lgiavedoni.android.franq.service.event.EventService;
import org.lgiavedoni.android.franq.service.phone.location.updatelocation.UpdateLocationStrategy;

public class UpdateLocationByGSMCellChangeStrategy implements UpdateLocationStrategy {

	private final MyEventListener eventListener = new MyEventListener();

	public void applayStrategy() {
		EventService.inst.addObserver(eventListener);
	}

	public void cancelStrategy() {
		EventService.inst.removeObserver(eventListener);
	}

	private static class MyEventListener extends EventListener {

		@Override
		public void exec(final Event event) {
			PositionManager.inst.tryToUpdatePosition();
		}

		@Override
		public Class getClassEvent() {
			return GSMCellChangeEvent.class;
		}
	}
}
